package com.wc.alorithm_blue_bridge._DFS.Q4234;

import java.io.*;

/**
 * @Author congege
 * @Description
 *
 * 小怂爱水洼
 * https://www.lanqiao.cn/problems/4234/learning/?page=1&first_category_id=1
 * @Date Created in 2023/11/27-21:26
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] map = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                map[i][j] = sc.nextInt();
            }
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (map[i][j] != 0) {
                    ans = Math.max(dfs(map, i, j), ans);
                }
            }
        }
        System.out.println(ans);
    }

    public static long dfs(int[][] map, int x, int y) {
        if (x < 0 || x == map.length || y < 0 || y == map[0].length || map[x][y] == 0) {
            return 0;
        }
        long ans = map[x][y];
        map[x][y] = 0;
        int up = x - 1;
        int down = x + 1;
        int left = y - 1;
        int right = y + 1;
        ans += dfs(map, up, y);
        ans += dfs(map, down, y);
        ans += dfs(map, x, left);
        ans += dfs(map, x, right);
        return ans;
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (Exception e) {
                return -1;
            }
            return (int) in.nval;
        }
    }
}
